import router from './router'

import {getAccessToken} from '@/utils/auth'
// import {getPermission} from "@/api/login";
// import {activateRouter} from "@/utils/activateRouter";

router.beforeEach((to, from, next) => {
    if (getAccessToken()) {
        // console.log(router.getRoutes().length)
        if (to.path === '/login') {
            next({path: '/'})
        }
        // 解决动态路由丢失的问题
        // console.log(router.getRoutes())
/*        if (router.getRoutes().length === 2) {
            getPermission().then(res => {
                activateRouter(res.data)
            }).catch(() => {
                console.log(router.getRoutes())
            })
        }*/
        next()
    } else {
        // 没有token
        if (to.path === '/login') {
            // 直接进入
            next()
        } else if (to.path === '/register') {
            next()
        } else {
            next('/login') // 否则全部重定向到登录页
        }
    }
})

router.afterEach(() => {

})
